package com.zsix.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.zsix.common.common.page.BaseController;
import com.zsix.common.common.page.PageDataTable;
import com.zsix.common.dto.controllerParams.StatAnalysisParams;
import com.zsix.common.entity.process.ProcessManage;
import com.zsix.common.entity.taskAssignee.GenerWork;
import com.zsix.common.util.ResultRes;
import com.zsix.framework.aspectj.annotation.OperLog;
import com.zsix.framework.aspectj.operate.LogConst;
import com.zsix.system.service.IProcessManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/processManage")
public class ProcessManageController extends BaseController {
    @Autowired
    private IProcessManageService processManageService;
    /**
     * 获取所有启动的流程实例
     * @param processManage
     * @return
     */
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取所有启动的流程实例")
    @PostMapping(value = "/getProcessManageListPage")
    public PageDataTable getProcessManageListPage(@RequestBody ProcessManage processManage) {
        startPage();
        List<ProcessManage> list=processManageService.getProcessManageListPage(processManage);
        return getDataTable(list);
    }
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取流程实例参数")
    @PostMapping(value = "/getManageParams")
    public ResultRes getManageParams(@RequestBody ProcessManage processManage) {
        try{
            return ResultRes.success(processManageService.getManageParams(processManage));
        }
        catch (Exception ex){
            return ResultRes.error(ex.getMessage());
        }
    }
    /**
     * 获取所有任务分页
     * @param processManage
     * @return
     */
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取所有任务列表")
    @PostMapping(value = "/getTaskManageListPage")
    public PageDataTable getTaskManageListPage(@RequestBody ProcessManage processManage) {
        startPage();
        List<GenerWork> list=processManageService.getTaskManageListPage(processManage);
        return getDataTable(list);
    }

    /**
     * 获取流程统计数据
     * @param statAnalysisParams
     * @return
     */
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取流程统计数据")
    @PostMapping(value = "/getStatAnalysisData")
    public ResultRes getStatAnalysisData(@RequestBody StatAnalysisParams statAnalysisParams) {
        try{
            return ResultRes.success(processManageService.getStatAnalysisData(statAnalysisParams));
        }
        catch (Exception ex){
            return ResultRes.error(ex.getMessage());
        }
    }

    /**
     * 获取我发起的流程列表
     * @param params
     * @return
     */
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取我发起的流程列表")
    @PostMapping(value = "/getMyStartListPage")
    public ResultRes getMyStartListPage(@RequestBody JSONObject params) {
        try{
            return ResultRes.success(processManageService.getMyStartListPage(params));
        }
        catch (Exception ex){
            return ResultRes.error(ex.getMessage());
        }
    }

    /**
     * 获取我审核的流程列表
     * @param params
     * @return
     */
    @OperLog(operModul = "流程实例相关" , operType = LogConst.OTHER , operDesc = "获取我审核的流程实例列表")
    @PostMapping(value = "/getMyProcessPage")
    public ResultRes getMyProcessPage(@RequestBody JSONObject params) {
        try{
            return ResultRes.success(processManageService.getMyProcessPage(params));
        }
        catch (Exception ex){
            return ResultRes.error(ex.getMessage());
        }
    }
}
